package com.crdeng.business.converter;

import com.crdeng.business.entity.ProductCategory;
import com.crdeng.business.vo.ProductCategoryVO;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 转换
 */


public class ProductCategoryConverter {

    /**
     * 转换成VO类
     * @param productCategories
     * @return
     */
    public static List<ProductCategoryVO> converterToTreeNodeeVo(List<ProductCategory> productCategories){
        List<ProductCategoryVO> nodes=new ArrayList<>();
        if (!CollectionUtils.isEmpty(productCategories)){
            for (ProductCategory productCategory : productCategories) {
                ProductCategoryVO productCategoryVO = new ProductCategoryVO();
                BeanUtils.copyProperties(productCategory,productCategoryVO);
                nodes.add(productCategoryVO);
            }

        }
        return nodes;
    }


    public  static ProductCategory  converterToProductCategory(ProductCategoryVO productCategoryVO){
        ProductCategory productCategory = new ProductCategory();
        BeanUtils.copyProperties(productCategoryVO,productCategory);

        return productCategory;
    }

}
